import * as types from "./mutation-types";
import Api from "api/api";
const state = {
  questionClassList: [],
  curQuestionClass: {}
};

const getters = {
  questionClassList: state => state.questionClassList,
  curQuestionClass: state => state.curQuestionClass
};

const actions = {
  getQuestClassListS({ commit }, param) {
    return Api.getQuestClassList(param).then(ret => {
      commit(types.UPDATE_QUESTCLASS_LIST, ret.data.data);
      return ret;
    });
  },
  getQuestClassS({ commit }, id) {
    return Api.getQuestClass({ id: id }).then(ret => {
      commit(types.UPDATE_CURRENT_QUESTCLASS, ret.data.data);
      return ret;
    });
  },
  addOrUpdateQuestClassS({ commit }, payload) {
    return Api.addOrUpdateQuestClass({ body: payload }).then(ret => {
      return ret;
    });
  },

  deleteQuestClassS({ commit }, param) {
    return Api.deleteQuestClass(param).then(ret => {
      return ret;
    });
  }
};

const mutations = {
  [types.INIT_CURRENT_QUESTCLASS](state) {
    state.curQuestionClass = {
      clazz: ""
    };
  },
  [types.UPDATE_QUESTCLASS_LIST](state, payload) {
    state.questionClassList = payload;
  },
  [types.UPDATE_CURRENT_QUESTCLASS](state, payload) {
    state.curQuestionClass = payload;
  }
};
export default {
  state,
  getters,
  actions,
  mutations
};
